<?php
include_once "topo.php";
if(logado()){
    if($_SESSION["ci_user_nivel"] == 2){ header("location:index.php"); }
    ?>
        <h3>Setor</h3>
        <a href="setSetor.php" title="Novo"><button>Novo</button></a><br><br>
        <table>
            <tr>
                <th>ID</th>
                <th>Descrição</th>
                <th>E-Mail</th>
                <th></th>
            </tr>
            <?php
            $sql = "select id from ci_setor";
            $db = new db(config::$driver);
            $conexao = $db->conecta();
            $result = $db->query($sql, $conexao);
            $db->close($conexao);
            
            $zb = 0;
            while($ids = $db->fetch_array($result)){
                $setor = new setor();
                $setor->carregar($ids[0]);
                
                if($zb == 0){
                    echo "<tr class='zb'>";
                    $zb = 1;
                }else{
                    echo "<tr>";
                    $zb = 0;
                }
                echo "
                    <td>".$setor->get_id()."</td>
                    <td>".$setor->get_descricao()."</td>
                    <td>".$setor->get_email()."</td>
                    <td><a href='setSetor.php?id=".$setor->get_id()."' title='Alterar'>Alterar</td>
                </tr>
                ";
                
                unset($setor);
            }
            ?>
        </table>
    <?php
}else{
    header("location: login.php");
}
include_once "rodape.php";
?>
